package com.ggggeeennn.studentUser.service.Impl;

import com.ggggeeennn.common.utils.PageUtils;
import com.ggggeeennn.exam.domain.ExamManage;
import com.ggggeeennn.student.mapper.StudentManageMapper;
import com.ggggeeennn.studentUser.mapper.ExamMapper;
import com.ggggeeennn.studentUser.service.ExamService;
import com.ggggeeennn.student.domain.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamServiceImpl implements ExamService {

    @Autowired
    private StudentManageMapper studentManageMapper;
    @Autowired
    private ExamMapper examMapper;

    public List<ExamManage> selectExamList(Long userId,Integer pageNum,Integer pageSize){

        //从学生表中根据user_id查出major,也就是user（学生）所属专业
        Student student=studentManageMapper.selectStudentByUserId(userId);
        //启动分页
        PageUtils.startPage(pageNum,pageSize);
        //再根据major查出下所有的考试(前提是改考试的字段is_public为1,只有以发布的考试才能看到)
        return examMapper.selectExamListByMajor(student.getMajor());
    }

}
